//
// Created by steven on 2017/2/27.
// Copyright (c) 2017 steven. All rights reserved.
//

#import "GMOrderDetailViewController.h"


@implementation GMOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupMainView];
    [self renderView];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    // order content view
    [self.orderContentView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:18];
    [self.orderContentView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:18];
    [self.orderContentView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:48];
    [self.orderContentView autoSetDimension:ALDimensionHeight toSize:370];
    
    // order time label
    [self.orderTimeLabel autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.orderTimeLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:55];
    
    // guard count label
    [self.guardCountLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:55];
    [self.guardCountLabel autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.orderTimeLabel withOffset:4];
    
    // order no label
    [self.orderNoLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:55];
    [self.orderNoLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.orderTimeLabel withOffset:-4];
    
    // order detail label
    [self.orderDetailLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:55];
    [self.orderDetailLabel autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.guardCountLabel withOffset:-18];
}

- (void)setupMainView {
    self.navigationItem.title = @"订单详情";
    [self.view addSubview:self.orderContentView];
    [self.orderContentView addSubview:self.orderDetailLabel];
    [self.orderContentView addSubview:self.guardCountLabel];
    [self.orderContentView addSubview:self.orderTimeLabel];
    [self.orderContentView addSubview:self.orderNoLabel];
}

- (void)renderView {
    
    self.guardCountLabel.text = [NSString stringWithFormat:@"守卫侠个数: %@ 个", self.orderModel.count];
    self.orderTimeLabel.text = [NSString stringWithFormat:@"购买时间: %@", self.orderModel.buyTime];
    self.orderNoLabel.text = [NSString stringWithFormat:@"订单号: %@", self.orderModel.outTradeNo];
}

- (UIView *)orderContentView {
    if (!_orderContentView) {
        _orderContentView = [[UIView alloc] init];
        UIImage *backgroundImgae = [UIImage imageNamed:@"oreder-detail-background"];
        _orderContentView.backgroundColor = [UIColor colorWithPatternImage:backgroundImgae];
    }
    
    return _orderContentView;
}

- (UILabel *)orderDetailLabel {
    if (!_orderDetailLabel) {
        _orderDetailLabel = [[UILabel alloc] init];
        _orderDetailLabel.font = [UIFont systemFontOfSize:16];
        _orderDetailLabel.text = @"订单详情";
        _orderDetailLabel.textColor = BUTTON_ACTIVE_COLOR;
    }
    
    return _orderDetailLabel;
}

- (UILabel *)guardCountLabel {
    if (!_guardCountLabel) {
        _guardCountLabel = [[UILabel alloc] init];
        _guardCountLabel.font = [UIFont systemFontOfSize:14];
    }
    
    return _guardCountLabel;
}

- (UILabel *)orderTimeLabel {
    if (!_orderTimeLabel) {
        _orderTimeLabel = [[UILabel alloc] init];
        _orderTimeLabel.font = [UIFont systemFontOfSize:14];
    }
    
    return _orderTimeLabel;
}

- (UILabel *)orderNoLabel {
    if (!_orderNoLabel) {
        _orderNoLabel = [[UILabel alloc] init];
        _orderNoLabel.font = [UIFont systemFontOfSize:14];
    }
    
    return _orderNoLabel;
}
@end
